package com.semidata.rtd.core.iplib;

public class IPEntry implements Comparable<IPEntry> {
    private long start;
    private long end;
    private String code;

    public IPEntry(long start, long end, String code) {
        super();
        this.start = start;
        this.end = end;
        this.code = code;
    }

    public boolean contains(long ipLong) {
        return this.start <= ipLong && this.end >= ipLong;
    }

    public boolean before(long ipLong) {
        return this.end < ipLong;
    }

    public long getStart() {
        return start;
    }

    public long getEnd() {
        return end;
    }

    public String getCode() {
        return code;
    }

    @Override
    public String toString() {
        return "[start:" + this.start + ",end:" + this.getEnd() + ",code:" + this.code + "]";
    }

    @Override
    public int compareTo(IPEntry o) {
        if (o == null) {
            return 1;
        }
        return (int) (this.start - o.getStart());
    }
}
